<?php
namespace Admin\Controller;
class PageController extends CommonController{
	public  $exec_comfunc  = 'index';//index,add,edit,delete

	public function index(){
		$module = $this->_get('module', '对不起，您的操作有误！');
		$model = D('Page');
		
		$where['module'] = $module;
		$info = $model->where($where)->find();
		if(IS_POST){
			if($data = $model->create()){
				if(!$info){
					$data['module']      = $module;
					$data['content']     = htmlspecialchars_decode($data['content']);
					$data['create_time'] = time();
					$data['edit_time']   = time();
					if(false === $model->add($data)) {
						$this->error('修改失败！');
					}
				}else{
					$data['content']   = htmlspecialchars_decode($data['content']);
					$data['edit_time'] = time();
					if(false === $model->where($where)->save($data)) {
						$this->error('修改失败！');
					}
				}
				$this->success('修改成功！', U('index', array('module' => $module)));
			}else{
				$this->error($model->getError());
			}
		}
		$this->assign('info', $info);
		$this->display();
	}
}